/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.yanzhenjie.andserver.dialog;

import com.shaohui.bottomdialog.BaseOsDiaLog;

import com.yanzhenjie.hos.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.utils.TextAlignment;
import ohos.app.Context;

public class BottomDialog extends BaseOsDiaLog {
    private Context mContext;
    private Text address;
    private String ip;

    public BottomDialog(Context context, String ip) {
        super(context);
        this.mContext = context;
        this.ip = ip;
    }

    @Override
    protected int getDiaLogLayout() {
        return ResourceTable.Layout_dialog;
    }

    @Override
    protected int getAlignment() {
        return TextAlignment.TOP;
    }

    @Override
    protected DiaLogSize getDiaLogSize() {
        return new DiaLogSize(DisplayUtils.getWindowHeight(mContext), 600);
    }

    @Override
    protected void onCreateDiaLog(Component component) {
        super.onCreateDiaLog(component);
        address = (Text) component.findComponentById(ResourceTable.Id_address);
        //逻辑处理
        component.findComponentById(ResourceTable.Id_hide).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                hide();

            }
        });
        //  String url = "http://" + NetUtilsWork.getLocalIPAddress() + ":" + CoreService.port + "/";
        address.setText(ip);
    }

    public static void showBottomDialog(Context context, String ip) {
        new BottomDialog(context, ip)
                .setAutoClosable(true)
                .show();
    }
}
